package com.link2room.aeriabots.controller.manager;

import com.link2room.aeriabots.dto.param.base.WxComponentParamDto;
import com.link2room.common.constant.DefaultValue;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.aeriabots.facade.IWXComponentFacadeService;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.link2room.aeriabots.constant.PermissionConstant.wxAuthorizerURL;

/**
 * 三方平台获取公众号授权相关
 * Created by LN on 2016/9/2.
 */
@Api(tags = "三方平台获取公众号授权相关")
@RestController
@RequestMapping("/manager/AuthorizerURL")
public class WxOfficialAccountsComponentAuthorizerURLManagerController {
    @Resource
    private IWXComponentFacadeService wxComponentFacadeService;

    @ApiOperation(value = "微信菜单获取", response = String.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "lhotelCode", value = "酒店代码", required = true, defaultValue = DefaultValue.LHOTEL_CODE, paramType = "query"),
            @ApiImplicitParam(name = "appid", value = "微信公众号appid", required = true, paramType = "query"),
    })
    @RequestMapping(method = RequestMethod.GET)
    @L2RPermissionResources(value = wxAuthorizerURL, name = "三方平台获取公众号授权相关")
    public BaseResultDto getAuthorizerURL(
            @RequestParam(name = "lhotelCode",required = true)String hotelCode,
            @RequestParam(name = "appid",required = true) String appid
    ) throws Exception {
        WxComponentParamDto paramDto = new WxComponentParamDto();
        paramDto.setLhotelCode(hotelCode);
        paramDto.setAppId(appid);
        String url = wxComponentFacadeService.getOfficialAccountsAuthorizerURL(paramDto);
        BaseResultDto dto = new BaseResultDto();
        dto.setResultCode(0);
        dto.setResultInfo(url);
        return dto;
    }
}
